import request from '@/utils/request'

// 获取文章分页列表
export function getArticleList(params) {
  return request({
    url: '/article/paged',
    method: 'get',
    params
  })
}

// 条件查询文章
export function queryArticles(params) {
  return request({
    url: '/article/query',
    method: 'get',
    params
  })
}

// 获取单个文章详情
export function getArticleDetail(articleId) {
  return request({
    url: `/article/${articleId}`,
    method: 'get'
  })
}

// 创建文章
export function addArticle(data) {
  return request({
    url: '/article',
    method: 'post',
    data,
    params: { userId: data.userId } 
  })
}

// 更新文章
export function updateArticle(data) {
  return request({
    url: '/article',
    method: 'put',
    data
  })
}

// 更新文章状态
export function updateArticleStatus(articleId, status) {
  return request({
    url: `/article/${articleId}/status`,
    method: 'put',
    params: { status }
  })
}

// 删除文章
export function deleteArticle(articleId) {
  return request({
    url: `/article/${articleId}`,
    method: 'delete'
  })
}

// 获取文章分类树
export function getArticleCategoryTree(activeOnly = false) {
  return request({
    url: '/ArticleCategory/tree',
    method: 'get',
    params: { activeOnly }
  })
}

// 添加文章分类
export function addArticleCategory(data) {
  return request({
    url: '/ArticleCategory',
    method: 'post',
    data
  })
}

// 更新文章分类
export function updateArticleCategory(data) {
  return request({
    url: '/ArticleCategory',
    method: 'put',
    data
  })
}

// 切换分类激活状态
export function toggleArticleCategoryActive(categoryId) {
  return request({
    url: `/ArticleCategory/${categoryId}/toggle-active`,
    method: 'put'
  })
}

// 删除文章分类
export function deleteArticleCategory(categoryId) {
  return request({
    url: `/ArticleCategory/${categoryId}`,
    method: 'delete'
  })
}

// 检查分类名称是否唯一
export function checkCategoryNameUnique(params) {
  return request({
    url: '/ArticleCategory/check-name',
    method: 'get',
    params: {
      name: params.name,
      parentId: params.parentId,
      excludeId: params.id 
    }
  })
} 

// 获取启用的文章分类树（用于文章编辑）
export function getActiveArticleCategoryTree() {
  return request({
    url: '/ArticleCategory/tree',
    method: 'get',
    params: { activeOnly: true }
  })
} 